// Helper class to provide the localStorage keys
function StorageNames() {
}
StorageNames.FREQUENCY 		= "_frequency_in_seconds";
StorageNames.DURATION  		= "_duration_in_seconds";
StorageNames.SOUND_SETTING  = "_play_Sound";
StorageNames.SOUND_FILE     = "_notification_audio_file";

// Convert given input to a boolean
function parseBoolean(input)
{
	if(input == "true" || input == "1" || input == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function setAudioNotificationSetting(value) {
	localStorage.setItem("micro"+StorageNames.SOUND_SETTING, value);
	localStorage.setItem("macro"+StorageNames.SOUND_SETTING, value);
};

function isSettingsStale() {
	var isSettingsStale = localStorage.getItem("settingsStale");
	return parseBoolean(isSettingsStale);
};

function markSettingsStale(value) {
	localStorage.setItem("settingsStale", value);
}

function playSound(MICRO_BREAK_NOTIFICATION_AUDIO_FILE) {
	// Play the sound on a different thread
	setTimeout(function() {
		var alertSound = new Audio(MICRO_BREAK_NOTIFICATION_AUDIO_FILE);
		alertSound.play();
	}, 50);
}

// http://www.netlobo.com/url_query_string_javascript.html
// Get the query string variables from the URL
function getQueryStringValue(key) {
  key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  
  var regexS = "[\\?&]" + key + "=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );

  if (results == null) {
      return "";
  }
  else {
      var returnValue = results[1].replace(/%20/g, " ");
      return returnValue;
  }
}

Function.prototype.bind = function(obj) { 
	  var method = this, 
	   boundReference = function() { 
	    return method.apply(obj, arguments); 
	   }; 
	  
	  return boundReference; 
}